<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$return['ischecklogin']=model('jy_weishop/member')->checklogin('','','','',true);
	$return['list']=array();
	$tuilogid=intval($_RQ['tuilogid']);
	$_SESSION['tuilogid']=$tuilogid;
	$return['params']=array('tuilogid'=>$tuilogid,'ordersn'=>$_RQ['ordersn']?:'');
	if($this->setting['withdrawtype']){
		$withdrawtype=array();
		$wxapppay_types=array();
		$check=strstr($this->setting['withdrawtype'],'credit');
		if($check){
			$withdrawtype['credit']=$this->pay_types['credit'];
			$wxapppay_types[]=array(
				'key'=>'credit',
				'title'=>$this->pay_types['credit'],
			);
			$pay_type='credit';
		}
		$check=strstr($this->setting['withdrawtype'],'wechat');
		if($check){
			$withdrawtype['wechat']=$this->pay_types['wechat'];
			$wxapppay_types[]=array(
				'key'=>'wechat',
				'title'=>$this->pay_types['wechat'],
			);
			$pay_type=$pay_type?:'wechat';
		}
		$check=strstr($this->setting['withdrawtype'],'alipay');
		if($check){
			$withdrawtype['alipay']=$this->pay_types['alipay'];
			$wxapppay_types[]=array(
				'key'=>'alipay',
				'title'=>$this->pay_types['alipay'],
			);
			$pay_type=$pay_type?:'alipay';
		}
		$check=strstr($this->setting['withdrawtype'],'union');
		if($check){
			$withdrawtype['union']=$this->pay_types['union'];
			$wxapppay_types[]=array(
				'key'=>'union',
				'title'=>$this->pay_types['union'],
			);
			$pay_type=$pay_type?:'union';
		}
		$check=strstr($this->setting['withdrawtype'],'downline');
		if($check){
			$withdrawtype['downline']=$this->pay_types['downline'];
			$wxapppay_types[]=array(
				'key'=>'downline',
				'title'=>$this->pay_types['downline'],
			);
			$pay_type=$pay_type?:'downline';
		}
		$return['pay_types']=$withdrawtype;
	}else{
		$return['pay_types']=$this->pay_types;
		$pay_type='credit';
	}
	$wxapppay_types=array();
	foreach($return['pay_types'] as $k=>$pv){
		$wxapppay_types[]=array(
			'key'=>$k,
			'title'=>$pv,
		);
	}
	$return['wxapppay_types']=$wxapppay_types;
	$check=strstr($this->setting['withdrawtype'],'alipay');
	if($check){
		$type_array[1]='提现到支付宝';
        $post1=$this->get('balance',array('pay_type'=>'alipay','uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),array('alipay','realname','mobile'),'id desc');
	}
	$check=strstr($this->setting['withdrawtype'],'union');
	if($check){
		$type_array[2]='提现到银行卡';
        $post2=$this->get('balance',array('pay_type'=>'union','uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),array('bankname','bankcard','realname','mobile'),'id desc');
        $post2['bankcard1']=$post2['bankcard'];
	}
    if($post1 || $post2) {
        $return['post'] = array_merge($post1, $post2);
    }else{
		$balance=$this->get('balance',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),array('bankname','bankcard','realname','mobile'),'id desc');
		$return['post']['mobile']=$balance['mobile'];
	}
	$return['tuilog']=pdo_get('jy_newcar_tuilog',array('id'=>$tuilogid,'uniacid'=>$_SESSION['uniacid']));
	$return['post']['pay_type']=$pay_type;
	set_html('title','奖励明细');
	exi($return);
}
if($_RQ['op']=='list'){
	$params=array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid'],'type'=>0);
	if($_RQ['ordersn']){
		$params['ordersn']=$_RQ['ordersn'];
	}
	if($_RQ['tuilogid']){
		$params['tuilogid']=$_RQ['tuilogid'];
	}
	if(!$_RQ['ordersn'] && !$_RQ['tuilogid']){
		exi('请从推广组或订单进入！','error');
	}
	$psize=20;
	$pindex=intval($_RQ['page'])?:1;
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'orderby'=>'monthtime asc',
	);
	$list=$this->get_list('yufee',$parameter);
	if(!$list){
		exi('none');
	}
	foreach($list as &$item){
		$item['month']=$item['year'].'-'.$item['month'];
		$item['statustitle']=$this->yufee_status[$item['status']];	
		$item['createtime']=date('Y-m-d H:i',$item['createtime']);
		$item['cantx']=$item['monthtime']<time()?1:0;
		if($item['cantx']){
			$item['service_money']=intval($this->setting['balance_per']*$item['money'])/100;
			$item['cash_money']=$item['money']-$item['service_money'];
		}
	}
	exi($list);
}
//结算
if($_RQ['op']=='balance'){
	$post=get_postdata();
	$this->model('yufee')->create_balance($_SESSION['uid'],$post);
	exi('申请提现成功！','','/gou.yufee/main/tuilogid='.$_SESSION['tuilogid']);
}
?>